[id].vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- 导航栏 -->
  5. <HomePageNavigation1></HomePageNavigation1>
  6. <!-- Banner1 -->
  7. <HomeBanner1></HomeBanner1>
  8. <!-- 列表页广告一 -->
  9. <!-- <HomeTopTen :imgurl="adList[0]" v-if="adList[0]"></HomeTopTen> -->
  10. <!-- 面包屑导航 -->
  11. <div class="breadcrumb">
  12. <div class="inner">
  13. <span class="location">当前位置:</span>
  14. <el-breadcrumb :separator-icon="ArrowRight">
  15. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  16. <el-breadcrumb-item :to="{ path: `/primaryNavigation/${listid}` }" v-show="name">{{ name
  17. }}</el-breadcrumb-item>
  18. <el-breadcrumb-item>{{ newsDetail.con_title }}</el-breadcrumb-item>
  19. </el-breadcrumb>
  20. </div>
  21. </div>
  22. <!-- 资讯列表 -->
  23. <div class="newsDetail">
  24. <div class="inner">
  25. <div class="innerLeft">
  26. <!-- <div class="LeftTop">
  27. <h1>{{ newsDetail.list_title }}</h1>
  28. </div> -->
  29. <div class="leftBottomTitle">{{ newsDetail.con_title }}</div>
  30. <div class="leftBottom" v-html="newsDetail.content"></div>
  31. </div>
  32. <div class="innerRight">
  33. <div class="rightMenuTitle">导航列表</div>
  34. <ul>
  35. <li v-for="(item, index) in bottomMenu" :key="index">
  36. <NuxtLink :to="`/speciaArticle/${item.id}`" target="_blank"
  37. v-if="item.id == pageId && item.id != 7" class="active">{{ item.name }}</NuxtLink>
  38. <NuxtLink :to="`/speciaArticle/${item.id}`" target="_blank"
  39. v-else-if="item.id != pageId && item.id != 7">{{ item.name }}</NuxtLink>
  40. <NuxtLink :to="`/specialList/${item.id}`" target="_blank"
  41. v-if="item.id == 7 && pageId == 7 && routeHref == '/specialList/7'" class="active">{{
  42. item.name }}
  43. </NuxtLink>
  44. <NuxtLink :to="`/specialList/${item.id}`" target="_blank" v-else-if="item.id == 7">{{ item.name
  45. }}
  46. </NuxtLink>
  47. </li>
  48. </ul>
  49. </div>
  50. <div style="clear: both;"></div>
  51. </div>
  52. </div>
  53. <!-- 页面底部 -->
  54. <HomeFoot1></HomeFoot1>
  55. </template>
  56. <script setup>
  57. import { onMounted } from 'vue'
  58. import { ElBreadcrumb, ElBreadcrumbItem } from 'element-plus'
  59. import { ArrowRight } from '@element-plus/icons-vue'
  60. const nuxtApp = useNuxtApp();
  61. const axios = nuxtApp.$axios;
  62. //获得跳转过来的id
  63. const route = useRoute();
  64. const articleId = route.params.id; //获得该页面的id
  65. const listid = route.query.listId; //获得该页面的id
  66. const name = route.query.listName; //获得该页面的id
  67. const pageId = route.params.id; //获得该页面的id
  68. const routeHref = route.href;
  69. console.log(333333)
  70. console.log(route.href)
  71. const newsDetail = ref({})
  72. console.log(articleId)
  73. const routeNewsTtitle = ref("");
  74. //获得广告
  75. const adList = ref("");
  76. const aa = 'page'
  77. const getadList = async () => {
  78. try {
  79. const response = await axios.get(`/web/getWebsiteAdvertisement?ad_tag=${aa}`);
  80. adList.value = response.data;
  81. } catch (error) {
  82. console.error(error);
  83. }
  84. }
  85. onMounted(() => {
  86. //获得广告
  87. getadList()
  88. })
  89. // 定义响应式数据
  90. const seoData = ref({
  91. title: '三农资讯网',
  92. description: '默认描述',
  93. keywords: '默认关键词',
  94. image: 'https://example.com/default-image.jpg'
  95. });
  96. // 在 onMounted 钩子中获取数据
  97. onMounted(async () => {
  98. try {
  99. const response = await axios.get(`/web/getWebsiteCategoryHead?catid=${articleId}`);
  100. const data = response.data.website_head; // 假设接口返回的数据在 data 字段中
  101. console.log(seoData.value.title)
  102. // 更新 seoData
  103. seoData.value = {
  104. title: data.seo_title,
  105. description: data.seo_description,
  106. keywords: data.seo_keywords,
  107. image: data.seo_image
  108. };
  109. console.log(seoData.value.title)
  110. } catch (error) {
  111. console.error('获取 SEO 数据失败:', error);
  112. // 设置默认值
  113. seoData.value = {
  114. title: '三农资讯网',
  115. description: '默认描述',
  116. keywords: '默认关键词',
  117. image: 'https://example.com/default-image.jpg'
  118. };
  119. }
  120. });
  121. // 监听 seoData 的变化,动态设置 SEO 字段
  122. watch(seoData, (newVal) => {
  123. if (newVal.title) { // 确保 title 有值
  124. useSeoMeta({
  125. title: newVal.title, // 使用动态值
  126. description: newVal.description,
  127. ogTitle: newVal.title,
  128. ogDescription: newVal.description,
  129. ogImage: newVal.image,
  130. twitterTitle: newVal.title,
  131. twitterDescription: newVal.description,
  132. twitterImage: newVal.image,
  133. keywords: newVal.keywords
  134. });
  135. }
  136. }, { immediate: true });
  137. //获取详情
  138. const getNewsInfo = async () => {
  139. const response = await axios.get(`/web/getWebsiteFooterCategoryInfo?fcat_id=${articleId}`);
  140. newsDetail.value = response.data;
  141. console.log(newsDetail.value.title)
  142. if (newsDetail.value.title.length > 30) {
  143. routeNewsTtitle.value = newsDetail.value.title.substr(0, 30) + "...";
  144. }
  145. }
  146. //获得底部导航
  147. const bottomMenu = ref([]);
  148. const getBottomMenu = async () => {
  149. const response = await axios.get(`/web/getWebsiteFooterCategory`);
  150. bottomMenu.value = response.data;
  151. }
  152. onMounted(() => {
  153. //获得详情
  154. getNewsInfo()
  155. // 获得左侧导航
  156. getBottomMenu()
  157. })
  158. </script>
  159. <style lang="less" scoped>
  160. //导航条
  161. .breadcrumb {
  162. width: 100%;
  163. height: 22px;
  164. margin-bottom: 30px;
  165. font-family: Microsoft YaHei, Microsoft YaHei;
  166. font-weight: 400;
  167. font-size: 20px;
  168. color: #666666;
  169. line-height: 23px;
  170. text-align: left;
  171. font-style: normal;
  172. text-transform: none;
  173. .el-breadcrumb::v-deep {
  174. display: inline-block;
  175. vertical-align: -4px;
  176. }
  177. /deep/.el-breadcrumb__inner a,
  178. /deep/.el-breadcrumb__inner.is-link {
  179. color: #666666;
  180. font-weight: 400;
  181. text-decoration: none;
  182. transition: var(--el-transition-color);
  183. }
  184. span {
  185. font-family: Microsoft YaHei, Microsoft YaHei;
  186. font-weight: 400;
  187. font-size: 20px;
  188. color: #666666;
  189. line-height: 23px;
  190. text-align: left;
  191. font-style: normal;
  192. text-transform: none;
  193. }
  194. span:hover {
  195. color: #666666;
  196. }
  197. .location {
  198. margin-right: 20px;
  199. width: 100px;
  200. height: 22px;
  201. font-family: Microsoft YaHei, Microsoft YaHei;
  202. font-weight: 400;
  203. font-size: 20px;
  204. color: #666666;
  205. line-height: 23px;
  206. text-align: left;
  207. font-style: normal;
  208. text-transform: none;
  209. }
  210. }
  211. // 资讯列表
  212. .newsDetail {
  213. width: 100%;
  214. //height: 1400px;
  215. margin-bottom: 70px;
  216. .inner {
  217. width: 1200px;
  218. //height: 1400px;
  219. font-size: 16px;
  220. .innerLeft {
  221. //height: 1400px;
  222. float: right;
  223. .LeftTop {
  224. //height: 522px;
  225. margin-top: 50px;
  226. >h1 {
  227. line-height: 40px;
  228. margin-bottom: 30px;
  229. font-family: Microsoft YaHei, Microsoft YaHei;
  230. font-weight: bold;
  231. font-size: 30px;
  232. color: #333333;
  233. }
  234. >p {
  235. height: 18px;
  236. line-height: 18px;
  237. font-family: Microsoft YaHei, Microsoft YaHei;
  238. font-weight: 400;
  239. font-size: 14px;
  240. color: #999999;
  241. span {
  242. margin-right: 40px;
  243. }
  244. }
  245. >img {
  246. width: 680px;
  247. height: 382px;
  248. padding: 50px 0px 60px 55px;
  249. }
  250. }
  251. .leftBottomTitle {
  252. color: #028E21;
  253. font-size: 24px;
  254. font-weight: bold;
  255. height: 60px;
  256. line-height: 60px;
  257. }
  258. .leftBottom {
  259. width: 790px;
  260. font-size: 20px;
  261. border-top: 1px solid #139602;
  262. padding-top: 40px;
  263. >h3,
  264. >p {
  265. text-indent: 2em;
  266. width: 790px;
  267. font-family: Microsoft YaHei, Microsoft YaHei;
  268. font-size: 20px;
  269. color: #333333;
  270. line-height: 23px;
  271. padding-bottom: 30px;
  272. }
  273. >h3 {
  274. font-weight: 600px;
  275. }
  276. >p {
  277. font-weight: 400;
  278. }
  279. }
  280. }
  281. .innerRight {
  282. width: 279px;
  283. .rightMenuTitle {
  284. width: 279px;
  285. height: 69px;
  286. font-size: 22px;
  287. font-weight: bold;
  288. line-height: 58px;
  289. text-align: center;
  290. color: #fff;
  291. background: url("../../static/special/projectMoreTitle.png") no-repeat;
  292. margin-bottom: 30px;
  293. }
  294. ul {
  295. li {
  296. a {
  297. border-left: 5px solid #028E21;
  298. margin-bottom: 15px;
  299. font-size: 22px;
  300. display: block;
  301. height: 61px;
  302. line-height: 61px;
  303. color: #333333;
  304. text-align: center;
  305. background: #FBFBFB;
  306. }
  307. }
  308. }
  309. .active {
  310. border-left: 0;
  311. border: 1px solid #028E21;
  312. background: #fff;
  313. }
  314. }
  315. }
  316. }
  317. </style>